package com.jiazhong.shixi.bean.controller;

import com.jiazhong.shixi.bean.bean.User;
import com.jiazhong.shixi.bean.mapper.UserMapper;
import com.jiazhong.shixi.bean.util.JsonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserMapper userMapper;

    @RequestMapping("/find")
    public JsonResult find(User user) { //参数
        System.out.println(user);
        User u = userMapper.login(user);
        if (u == null) {
            // 登陆失败
            JsonResult result
                    = new JsonResult(false, 427, null, "账号或者密码错误");
            return result;
        } else {
            // 登陆成功
            JsonResult result = new JsonResult(true, 200, u.getId(), "");
            return result;
        }
    }

    @RequestMapping("/add")
    public JsonResult add(User user){
        userMapper.add(user);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }
}